package net.ojbk.study.twobox.service;

import net.ojbk.study.twobox.beans.po.Job;
import net.ojbk.study.twobox.beans.po.Jobcompany;
import net.ojbk.study.twobox.dao.JobMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.validation.BindingResult;

/**
 * Created with IntelliJ IDEA.
 * User: twobox
 * Date: 2019/4/17
 * Time: 23:02
 * Description: No Description
 */
@Service
public class JobcompanyService extends SupperService<Jobcompany> {

    @Autowired
    JobMapper jobMapper;

    @Override
    public void addOne(Jobcompany o, BindingResult br) throws Exception {
        this.validated(br, Jobcompany.class);
        this.dao.insert(o);
    }

    @Override
    public void deleteOne(int id) throws Exception {
        Job job = new Job();
        job.setJobcomid(id);
        if (jobMapper.selectCount(job) > 0)
            throw new Exception("检查crm_job表中没有jobcomId的存在,如果有则不允许删除");
        this.dao.deleteByPrimaryKey(id);
    }

    @Override
    public void updateOne(Jobcompany o, BindingResult br) throws Exception {
        this.validated(br, Jobcompany.class);
        this.dao.updateByPrimaryKeySelective(o);
    }
}
